# 简单：图片平滑器
class Solution:
    # def imageSmoother(self, img: List[List[int]]) -> List[List[int]]:
    def imageSmoother(self, img):
        n, m = len(img), len(img[0])
        ret = [[0]*m for i in range(n)]

        for i in range(n):
            for j in range(m):
                sum = 0
                tol = 0
                for t in range(max(0, i-1), min(n, i+2)):
                    for k in range(max(0, j-1), min(m, j+2)):
                        sum += img[t][k]
                        tol += 1

                ret[i][j] = sum//tol

        return ret


s = Solution()
print(s.imageSmoother([[100, 200, 100],
                       [200, 50, 200],
                       [100, 200, 100]]))
